package com.ch.doudemo.view;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.ch.doudemo.R;
import com.ch.doudemo.activity.SingleVideoActivity;
import com.ch.doudemo.adapter.SVideoCommentChildAdapter;
import com.ch.doudemo.base.MyApp;
import com.ch.doudemo.bean.CommonReqBean;
import com.ch.doudemo.bean.CommonResBean;
import com.ch.doudemo.bean.UrlBean;
import com.ch.doudemo.bean.VideoDetailResBean;
import com.ch.doudemo.util.HttpClientUtil;
import com.ch.doudemo.util.MyStringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

/**
 * Created by ColorRain on 2018/4/17.
 */

public class SVideoCommentItemview extends LinearLayout {
    @BindView(R.id.nameTV)
    TextView nameTV;
    @BindView(R.id.contentTV)
    TextView contentTV;
    @BindView(R.id.dzBT)
    TextView dzBT;
    @BindView(R.id.dateTV)
    TextView dateTV;
    @BindView(R.id.replayBT)
    TextView replayBT;
    @BindView(R.id.childBT)
    TextView childBT;
    @BindView(R.id.childLV)
    ListView childLV;
    private Context context;
    private MyApp myApp;

    private SVideoCommentChildAdapter sVideoCommentChildAdapter;
    private VideoDetailResBean.Responsebody thisItem;
    private SingleVideoActivity thisActivity;

    public SVideoCommentItemview(Context context) {
        super(context);
        this.context = context;
        LayoutInflater.from(context).inflate(R.layout.itemview_single_video_comment, this);
        ButterKnife.bind(this);
        thisActivity = (SingleVideoActivity) context;
        myApp = (MyApp) thisActivity.getApplication();
        sVideoCommentChildAdapter = new SVideoCommentChildAdapter(context);
        childLV.setAdapter(sVideoCommentChildAdapter);
    }

    public void bind(VideoDetailResBean.Responsebody item) {
        this.thisItem = item;
        nameTV.setText(item.getUser_name() + "：");
        contentTV.setText(item.getContent());
        dateTV.setText(item.getCreate_date());
        if (item.isGood()) {
            dzBT.setText("♥已赞" + item.getGood_num());
        } else {
            dzBT.setText("♡点赞" + item.getGood_num());
        }
        if(item.isExpend()){
            childLV.setVisibility(VISIBLE);
        }else{
            childLV.setVisibility(GONE);
        }
        if(null == item.getTwoList() || 0 == item.getTwoList().size()){
            childBT.setVisibility(GONE);
        }else{
            childBT.setVisibility(VISIBLE);
        }
        sVideoCommentChildAdapter.setItems(item.getTwoList());
        childLV.setAdapter(sVideoCommentChildAdapter);

    }

    @OnClick({R.id.replayBT, R.id.childBT, R.id.dzBT})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.dzBT:
                int curGoodNum = Integer.parseInt(dzBT.getText().toString().replace("♡点赞", "").replace("♥已赞", ""));
                thisActivity.requestChildGood(thisItem.getId(),dzBT,dzBT.getText().toString(),curGoodNum);
                break;
            case R.id.replayBT:
                thisActivity.showInputLayout(context.getString(R.string.huifu_sign),thisItem);
                break;
            case R.id.childBT:
                if(childLV.getVisibility() == VISIBLE){
                    childLV.setVisibility(GONE);
                    thisItem.setExpend(false);
                }else{
                    childLV.setVisibility(VISIBLE);
                    thisItem.setExpend(true);
                }
                break;
        }
    }

}
